using System;
using System.Data;
using Utils;
using Utils.DatabaseUtils;
using System.Collections;
using Utils.Entity;


namespace DCSLibrary
{
public class OrdersUI
{ 
	

	public OrdersUI() {}

	public int Add(int usersID, DateTime orderDate, byte orderStatus, String orderComment, String shippingFirstName, String shippingLastName, String shippingAddress1, String shippingAddress2, String shippingPhone, String shippingTye, String shippingCost, String paymentFirstName, String paymentLastName, String paymentAddress1, String paymentAddress2, String paymentPhone)
	{
		try
		{
			int result = SqlHelper.ExecuteNonQuery(Common.Conn,"Orders_Add",usersID,orderDate,orderStatus,orderComment,shippingFirstName,shippingLastName,shippingAddress1,shippingAddress2,shippingPhone,shippingTye,shippingCost,paymentFirstName,paymentLastName,paymentAddress1,paymentAddress2,paymentPhone);
			return result;
		}
		catch(Exception e) {return -1; }
	}

    public int Add(CartEntity cart)
    {
        try
        {
            OrderDetailUI objDetail = new OrderDetailUI();

            int orderId = Convert.ToInt32(SqlHelper.ExecuteScalar(Common.Conn, "Orders_Add", cart.UsersID, cart.OrderDate, cart.OrderStatus, cart.OrderComment, cart.ShippingFirstName, cart.ShippingLastName, cart.ShippingAddress1, cart.ShippingAddress2, cart.ShippingPhone, cart.ShippingTye, cart.ShippingCost, cart.PaymentFirstName, cart.PaymentLastName, cart.ShippingAddress1, cart.ShippingAddress2, cart.PaymentPhone));
            if (cart.ListProduct != null && cart.ListProduct.Count > 0)
            {
                foreach (CartProductEntity obj in cart.ListProduct)
                {
                    objDetail.Add(orderId, obj.ProductID, obj.Quatnity, obj.Price);
                }
            }
            return orderId;
        }
        catch (Exception e) { return -1; }
    }

	public int Update(int orderID, int usersID, DateTime orderDate, byte orderStatus, String orderComment, String shippingFirstName, String shippingLastName, String shippingAddress1, String shippingAddress2, String shippingPhone, String shippingTye, String shippingCost, String paymentFirstName, String paymentLastName, String paymentAddress1, String paymentAddress2, String paymentPhone)
	{
		try
		{
			int result = SqlHelper.ExecuteNonQuery(Common.Conn,"Orders_Update",orderID,usersID,orderDate,orderStatus,orderComment,shippingFirstName,shippingLastName,shippingAddress1,shippingAddress2,shippingPhone,shippingTye,shippingCost,paymentFirstName,paymentLastName,paymentAddress1,paymentAddress2,paymentPhone);
			return result;
		}
		catch(Exception e) {return -1; }
	}

	public int Delete(int orderID)
	{
		try
		{
			int result = SqlHelper.ExecuteNonQuery(Common.Conn,"Orders_Delete",orderID);
			return result;
		}
		catch(Exception e) {return -1; }
	}

	public int DeleteAll()
	{
		try
		{
			int result = SqlHelper.ExecuteNonQuery(Common.Conn,"Orders_DeleteAll");
			return result;
		}
		catch(Exception e) {return -1; }
	}

	public DataSet Get(int orderID)
	{
		try
		{
			DataSet result = SqlHelper.ExecuteDataset(Common.Conn,"Orders_Get",orderID);
			return result;
		}
		catch(Exception e) {return null; }
	}

	public DataSet GetAll()
	{
		try
		{
			DataSet result = SqlHelper.ExecuteDataset(Common.Conn,"Orders_GetAll");
			return result;
		}
		catch(Exception e) {return null; }
	}

} 
}
